package cn;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Author 刘野
 * @create 2021/12/10 23:00
 */
public class Beida {

    public static void main(String[] args) {
        Beida beida = new Beida();

        String word = "I am a student";
        Map<Character, Integer> map = new HashMap<>();


        beida.aaa(word,map);

        Set<Character> keys = map.keySet();
        Iterator<Character> ite = keys.iterator();
        while(ite.hasNext())
        {
            Character key = ite.next();
            Integer value = map.get(key);

            System.out.print((key+" "+value) + "\t");
        }


    }


    public void aaa(String a,Map map){
        // proMap存储所有字符和个数
        Map<Character, Integer> proMap = new HashMap<>();
        for(char c : a.replace(" ", "").toCharArray()){
            if (proMap.containsKey(c)){
                proMap.put(c,proMap.get(c)+1);
            }else {
                proMap.put(c, 1);
            }
        }

     //   for (int i = 0; i < proMap.size(); i++) { }

        for(char c : a.replace(" ", "").toCharArray()){
            if (proMap.get(c) >1){
                map.put(c,proMap.get(c));
            }


        }


















    }



}